package crm.base.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CommonUtils {
	private static final transient Log log = LogFactory.getLog(CommonUtils.class);

	public static Properties loadProperties(URL url, String info) {
		log.info("OSCache: Getting properties from URL " + url + " for " + info);

		Properties properties = new Properties();
		InputStream in = null;
		try {
			in = url.openStream();
			properties.load(in);
			log.info("OSCache: Properties read " + properties);
		} catch (Exception e) {
			log.error("OSCache: Error reading from " + url, e);
			log.error("OSCache: Ensure the properties information in " + url + " is readable and in your classpath.");
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				log.warn("OSCache: IOException while closing InputStream: " + e.getMessage());
			}
		}

		return properties;
	}

}
